package com.big.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.big.app.dao.PortraitArticleDao;
import com.big.app.entity.PortraitArticle;
import com.big.app.service.intf.PortraitArticleService;
import com.big.app.vo1.R;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

@Service
public class PortraitArticleServiceImpl implements PortraitArticleService {
    @Resource
    private PortraitArticleDao dao;
    @Override
    public R add(PortraitArticle article) {
        if(article!=null){
            article.setCtime(new Date());
            dao.insert(article);
            return R.ok();
        }
        return R.fail("网络异常");
    }

    @Override
    public R queryTop() {
        QueryWrapper<PortraitArticle> queryWrapper=new QueryWrapper<>();
        queryWrapper.orderByDesc("ctime");
        return R.ok(dao.selectList(queryWrapper));
    }

    @Override
    public R queryDetail(int id) {
        if (id>0){
            return R.ok(dao.selectById(id));
        }
        return R.fail("网络异常");
    }
}
